from django.db import models
from WashApp.models import Washers


# Create your models here.
class Users(models.Model):
    uid = models.CharField('用户', max_length=32, primary_key=True)
    uname = models.CharField('名字', max_length=16, default='')
    ugender = models.BooleanField('性别', default=False)
    uage = models.SmallIntegerField('年龄', default='')
    upassword = models.CharField('密码', max_length=32, default='')
    uupdate_time = models.DateTimeField('更新时间', auto_now=True)
    ucreate_time = models.DateTimeField('创建时间', auto_now_add=True)
    washers = models.ManyToManyField(Washers, through='Order')

    # 指定表名为users
    class Meta:
        db_table = 'users'


# 建立第三张表，记录Users和Washers的多对多关系
class Order(models.Model):
    user = models.ForeignKey(Users, on_delete=models.CASCADE)
    washer = models.ForeignKey(Washers, on_delete=models.CASCADE)
    timer = models.DateTimeField('创建时间', auto_now_add=True)

    # 指定表名为u_order
    class Meta:
        db_table = 'u_order'
